package com.weilian.ordering.view;

import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.weilian.ordering.common.Preferences;

public class ScreenSaveDialog {

	private Builder builder = null;
	private SeekBar seekBar = null;
	private Context context;
	private Preferences p;
	private int i = 0;
	
	public ScreenSaveDialog(Context context) {
		this.context = context;
		builder = new Builder(context);
		p = Preferences.getInstance(context);
		// TODO Auto-generated constructor stub
	}
	
	public void showDialog(){
		builder.setTitle("设置广告播放时间");
		seekBar = new SeekBar(context);
		seekBar.setMax(30);
		i = p.getScreenSave();
		seekBar.setProgress(i);
		seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				i = seekBar.getProgress();
				Toast.makeText(context, "当前选择"+i+"分钟", 0).show();
			}
			
			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				// TODO Auto-generated method stub
				
			}
		});
		builder.setView(seekBar);
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				p.setScreenSave(i);
			}
		});
		builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		});
		builder.show();
	}
	

}
